<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.dml_ordersn" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="dataForm.special_id" placeholder="用户码" clearable></el-input>
      </el-form-item>
      <el-form-item label="订单时间:">
        <el-date-picker
          v-model="value2"
          :format="'yyyy-MM-dd HH:mm:ss'"
          :value-format="'yyyy-MM-dd HH:mm:ss'"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="">
        <el-select v-model="dataForm.dml_status" placeholder="审核状态" clearable>
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
    <!--  <el-table-column
        prop="dmlId"
        header-align="center"
        align="center"
        min-width=""
        label="">
      </el-table-column>-->
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        min-width=""
        label="用户ID">
      </el-table-column>
      <el-table-column
        prop="specialId"
        header-align="center"
        align="center"
        min-width=""
        label="会员码">
      </el-table-column>
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        min-width="90"
        label="用户名">
      </el-table-column>
      <el-table-column
        prop="dmlOrdersn"
        header-align="center"
        align="center"
        min-width="160"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="dmlMoney"
        header-align="center"
        align="center"
        min-width=""
        :formatter="formatMoney"
        label="转入金额">
      </el-table-column>
      <el-table-column
        prop="dmlLog"
        header-align="center"
        align="center"
        min-width="110"
        label="详情">
      </el-table-column>
      <el-table-column
        prop="dmlStatus"
        header-align="center"
        align="center"
        label="审核状态">
        <template slot-scope="scope">
          <el-tag type="warning"v-if="scope.row.dmlStatus === 1" size="small" >审核中</el-tag>
          <el-tag v-if="scope.row.dmlStatus === 2" size="small" >通过</el-tag>
          <el-tag  type="danger" v-if="scope.row.dmlStatus === 3" size="small" >退回</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="dmlAddtimeStr"
        header-align="center"
        align="center"
        min-width="150"
        label="申请日期">
      </el-table-column>
      <el-table-column
        prop="dmlAudittimeStr"
        header-align="center"
        align="center"
        min-width="150"
        label="审批日期">
      </el-table-column>
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        min-width=""
        label="审核人">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" :disabled="(scope.row.dmlStatus === 2 || scope.row.dmlStatus === 3) ? true :false" @click="addOrUpdateHandle(scope.row.dmlId)">通过</el-button>
          <el-button type="text" size="small" :disabled="(scope.row.dmlStatus === 2 || scope.row.dmlStatus === 3) ? true :false" @click="deleteHandle(scope.row.dmlId)">退回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './v9drawmoneylog-add-or-update'
  export default {
    data () {
      return {
        value: '',
        visible: {},
        options: [{
          value: 2,
          label: '通过'
        }, {
          value: 1,
          label: '审核中'
        }, {
          value: 3,
          label: '退回'
        }],
        value: '',
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
        value2: ''
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      formatMoney: function (row, column) {
        return row.dmlMoneyStr ='¥'+ parseFloat(row.dmlMoney).toFixed(2) ;
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let start,end;
        if(this.value2){
          start=this.value2[0];
          end=this.value2[1];
        }
        this.$http({
          url: this.$http.adornUrl('/draw_money_log/v9drawmoneylog/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'dml_ordersn': this.dataForm.dml_ordersn,
            'special_id': this.dataForm.special_id,
            'dml_status': this.dataForm.dml_status,
            'start': start,
            'end': end
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 删除
      addOrUpdateHandle (id) {
        var params = {}
        params.id = id
        params.type = 1
        this.$confirm(`确定进行通过操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/draw_money_log/v9drawmoneylog/pass'),
            method: 'post',
            data: this.$http.adornData(params, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 退回
      deleteHandle (id) {
        var params = {}
        params.id = id
        params.type = 2
        this.$confirm(`确定进行退回操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/draw_money_log/v9drawmoneylog/pass'),
            method: 'post',
            data: this.$http.adornParams(params, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
